#!/bin/bash
PATH=/sbin:/usr/bin:$PATH


IPADDR=$1
TYPE=$2
GWNAME=$3
REMIP=$4

AGENTPATH=/opt/novell/groupwise/agents/bin/
PIDPATH=/var/run/gwack/
function error_exit
{
    echo $1 1>&2
    exit 1
}


if [ $TYPE == "domain" ]; then
	AGENT=gwmta
elif [ $TYPE == "po" ]; then
	AGENT=gwpoa
else
	error_exit "Agent Type not determined.. Exiting."

fi

PIDFILE=$PIDPATH$GWNAME.pid
killproc -p $PIDFILE $AGENTPATH$AGENT >& /dev/null

SUBNET=`ip addr show eth0 | grep $IPADDR | awk 'NR == 1{ print substr($2, length($2)-1)}'`;


if [ $REMIP = "yes" ]; then
	ip addr delete $IPADDR/$SUBNET dev eth0

	ip address show | grep $IPADDR > /dev/null
	if [ $? == 0 ]; then
	    error_exit " IP  address not removed  "
	fi
fi

if [ -f $PIDFILE ]; then
	rm $PIDFILE
fi

AGENTFILE=$PIDPATH$GWNAME.txt

if [ -f $AGENTFILE ]; then
	rm $AGENTFILE
fi

